package org.henzhi.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigManager {
	//创建当前类的类型的成员变量
     private static ConfigManager ConfigManager;
     //用于读取properties文件配置的类
     private Properties properties;
     //显示  私有化的无参构造方法
     private ConfigManager(){ 
    	 properties =new Properties();
     }
     
     public static ConfigManager getInstance(){
    	 
    	 if(ConfigManager==null){
    		 ConfigManager=new ConfigManager();
    	 }
    	 return ConfigManager;
     }
     
     //根据KEY获得VALUE
     public String getValue(String key) { 
    	 String configFile="db.properties";
    	 //创建输入流对象
    	 InputStream is=ConfigManager.class.getClassLoader().getResourceAsStream(configFile);
    	 
    	 //通过输入流加载载配置文件
    	 try {
			properties.load(is);
			 //释放资源
			 is.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	
		return properties.getProperty(key);
     }
    
    
}
